define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'order/index' + location.search,
                    add_url: 'order/add',
                    edit_url: 'order/edit',
                    del_url: 'order/del',
                    multi_url: 'order/multi',
                    import_url: 'order/import',
                    table: 'order',
                }
            });

            var table = $("#table");

            table.on('post-common-search.bs.table', function (event, table) {
                $('ul.nav-tabs li a[data-value="1"]').trigger('click');
                $(".form-commonsearch select[name=status]").val("1");
            });

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                searchFormVisible: true,
                showToggle: false,
                showColumns: false,
                search:false,
                showExport: false,
                showSearch: false,
                columns: [
                    [
                        {checkbox: true},
                        // {field: 'id', title: __('Id')},
                        {field: 'gymnasium.name', title: __('Gymnasium_id')},
                        // {field: 'user_id', title: __('User_id')},
                        // {field: 'user.username', title: __('User.username')},
                        {field: 'user.nickname', title: __('User_id'),operate:false},
                        {field: 'user.mobile', title: __('User_mobile')},
                        {field: 'numbers', title: __('Numbers')},
                        {field: 'transaction', title: __('Transaction')},
                        // {field: 'gymnasium_id', title: __('Gymnasium_id')},
                        // {field: 'gymnasium.name', title: __('Gymnasium.name')},
                        {field: 'good_type', title: __('Good_type'), searchList: {"1":__('Good_type 1'),"2":__('Good_type 2'),"3":__('Good_type 3'),"4":__('Good_type 4'),"5":__('Good_type 5')}, formatter: Table.api.formatter.normal},
                        {field: 'good_name', title: __('Good_name')},
                        {field: 'thumb_image', title: __('Thumb_image'), events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'total_price', title: __('Total_price'), operate:'BETWEEN'},
                        {field: 'status', title: __('Status'), searchList: {"-1":__('Status -1'),"0":__('Status 0'),"1":__('Status 1'),"2":__('Status 2'),"3":__('Status 3'),"4":__('Status 4')}, formatter: Table.api.formatter.status},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'pay_time', title: __('Pay_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'use_time', title: __('Use_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'end_time', title: __('End_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'end_number', title: __('End_number')},
                        {field: 'refund_time', title: __('Refund_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'validity_time', title: __('Validity_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});